package com.supercube.sport.yoga.service.impl;

import com.supercube.common.utils.CubeUtils;
import com.supercube.sport.yoga.dao.CorrelationVenueMapper;
import com.supercube.sport.yoga.dao.VenueInfoDTOMapper;
import com.supercube.sport.yoga.domain.CorrelationVenueDTO;
import com.supercube.sport.yoga.domain.UserCorrelationVenue;
import com.supercube.sport.yoga.domain.VenueInfoDTO;
import com.supercube.sport.yoga.service.VenueInfoService;
import com.supercube.sport.yoga.vo.VenueInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
@Transactional
public class VenueInfoServiceImpl implements VenueInfoService {

    @Autowired
    private VenueInfoDTOMapper venueInfoDTOMapper;
    @Autowired
    private CorrelationVenueMapper correlationVenueMapper;

    @Override
    public int save(VenueInfoDTO dto) {
        return venueInfoDTOMapper.insert(dto);
    }

    @Override
    public int update(VenueInfoDTO dto) {
        return venueInfoDTOMapper.updateByPrimaryKeyWithBLOBs(dto);
    }

    @Override
    public int deleteVenueInfoById(String id) {
        return venueInfoDTOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public VenueInfoVO queryVenueInfoById(String id) {
        return venueInfoDTOMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<VenueInfoVO> selectVenueInfoList(Map<String, Object> map) {
        CubeUtils.startPage(map);
        return venueInfoDTOMapper.selectVenueInfoList(map);
    }
    @Override
    public void saveUserCorrelationVenue(UserCorrelationVenue dto){
        dto.getVenueId().forEach(venueId->{
            CorrelationVenueDTO correlationVenueDTO = new CorrelationVenueDTO();
            correlationVenueDTO.setId(UUID.randomUUID().toString());
            correlationVenueDTO.setVenueId(venueId);
            correlationVenueDTO.setEmpId(dto.getUserId());
            correlationVenueMapper.insert(correlationVenueDTO);
        });
    }

    @Override
    public int deleteUserCorrelationVenue(Long userId) {
        return correlationVenueMapper.deleteByUserId(userId);
    }

    @Override
    public List<VenueInfoDTO> queryVenueInfoListByUserId(String userId) {
        return venueInfoDTOMapper.selectVenueInfoListByUserId(userId);
    }

    /**
     * 根据员工ID获取所关联的场馆ID
     *
     * @param employeeId
     * @return
     */
    public List<String> getVenueIdsByEmployeeId(Long employeeId) {
        return correlationVenueMapper.getVenueIdsByEmployeeId(employeeId);
    }
    public List<CorrelationVenueDTO> queryCorrelationVenueByUserId(Long userId) {
        return correlationVenueMapper.selectCorrelationVenueByUserId(userId);
    }
}
